﻿using UnityEngine;
using System.Collections;

/// <summary>
/// 用于卡片的显示
/// </summary>
public class CardSprite : MonoBehaviour
{
    private Card card;
    public UISprite sprite;
    private bool isSelected;

    void Start()
    {
    }

    /// <summary>
    /// sprite所装载的card
    /// </summary>
    public Card Poker
    {
        set
        {
            card = value;
            card.isSprite = true;
            SetSprite();
        }
        get { return card; }
    }

    /// <summary>
    /// 是否被点击中
    /// </summary>
    public bool Select
    {
        set { isSelected = value; }
        get { return isSelected; }
    }

	/// <summary>
	/// 设置图片深度
	/// </summary>
	public void SetDepth(int _depth)
	{
		sprite.depth = _depth;
	}

    /// <summary>
    /// 设置UISprite的显示
    /// </summary>
    void SetSprite()
    {
//        if (card.Attribution == CharacterType.Player || card.Attribution == CharacterType.Desk)
//        {
            sprite.spriteName = card.GetCardName;
//        }
//        else
//        {
//            sprite.spriteName = "SmallCardBack1";
//        }
    }

    /// <summary>
    /// 销毁精灵
    /// </summary>
    public void Destroy()
    {
        //精灵化false
        card.isSprite = false;
        //销毁对象
        Destroy(this.gameObject);
    }

    /// <summary>
    /// 卡牌点击
    /// </summary>
    public void OnClick()
    {
        if (card.Attribution == CharacterType.Player)
        {
            if (isSelected)
            {
                transform.localPosition -= Vector3.up * 10;
                isSelected = false;
            }
            else
            {
                transform.localPosition += Vector3.up * 10;
                isSelected = true;
            }
        }
    }
}
